import plugin from '../../../lib/plugins/plugin.js'
import fs from 'node:fs'
import YAML from 'yaml'
import gsCfg from '../../genshin/model/gsCfg.js'
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import { pluginRoot, pluginResources } from '../model/path.js'
import Reply from '../model/reply.js'
import { createRequire } from 'module';

export class zmLibrary extends plugin
{
	constructor ()
	{
   		super
		({
      			name: '适配词条库',
      			dsc: '面板均衡器适配词条库',
      			event: 'message',
      			priority: 9,
      			rule:
			[{
        				reg: '(#|\\\*)?(适配)(词条库)',
        				fnc: 'zmLibrary'
      			}]
    		})
  	}

	async zmLibrary () 
	{
//图像操作
		//获取最新require函数方式
		const require = createRequire(import.meta.url);
		//获取puppeteer工具包
		const puppeteer = require('puppeteer');
		//帮助图像异步操作
		(async () => {
  			const browser = await puppeteer.launch();
  			const page = await browser.newPage();
			//确定网页规格
  			await page.setViewport({
				width: 1920,
				height: 1280
			});
			//html生成图
  			await page.goto('file:///E:/Redis-x64-5.0.14.1/Miao-Yunzai/plugins/ZM/model/project/Library/Library.html');
 			// Output the screenshot as an image
  			await page.screenshot({ path: './plugins/ZM/resource/img/Library.png' });
 	 		await browser.close();
			//发送图像
			await this.reply(segment.image('file://'+pluginResources+'/img/Library.png'))
		})();		
		return false;
	}
}